package com.java110.mall.cart.api;

import com.alibaba.fastjson.JSONObject;
import com.java110.dto.housekeeping.HousekeepingResourceFeeDto;
import com.java110.po.housekeeping.HousekeepingResourceFeePo;
import com.java110.mall.cart.bmo.housekeepingResourceFee.IDeleteHousekeepingResourceFeeBMO;
import com.java110.mall.cart.bmo.housekeepingResourceFee.IGetHousekeepingResourceFeeBMO;
import com.java110.mall.cart.bmo.housekeepingResourceFee.ISaveHousekeepingResourceFeeBMO;
import com.java110.mall.cart.bmo.housekeepingResourceFee.IUpdateHousekeepingResourceFeeBMO;
import com.java110.utils.util.Assert;
import com.java110.utils.util.BeanConvertUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping(value = "/housekeepingResourceFee")
public class HousekeepingResourceFeeApi {

    @Autowired
    private ISaveHousekeepingResourceFeeBMO saveHousekeepingResourceFeeBMOImpl;
    @Autowired
    private IUpdateHousekeepingResourceFeeBMO updateHousekeepingResourceFeeBMOImpl;
    @Autowired
    private IDeleteHousekeepingResourceFeeBMO deleteHousekeepingResourceFeeBMOImpl;

    @Autowired
    private IGetHousekeepingResourceFeeBMO getHousekeepingResourceFeeBMOImpl;

    /**
     * 微信保存消息模板
     * @serviceCode /housekeepingResourceFee/saveHousekeepingResourceFee
     * @path /app/housekeepingResourceFee/saveHousekeepingResourceFee
     * @param reqJson
     * @return
     */
    @RequestMapping(value = "/saveHousekeepingResourceFee", method = RequestMethod.POST)
    public ResponseEntity<String> saveHousekeepingResourceFee(@RequestBody JSONObject reqJson) {

        Assert.hasKeyAndValue(reqJson, "resId", "请求报文中未包含resId");
        Assert.hasKeyAndValue(reqJson, "resName", "请求报文中未包含resName");
        Assert.hasKeyAndValue(reqJson, "configId", "请求报文中未包含configId");
        Assert.hasKeyAndValue(reqJson, "feeName", "请求报文中未包含feeName");
        Assert.hasKeyAndValue(reqJson, "shopId", "请求报文中未包含shopId");


        HousekeepingResourceFeePo housekeepingResourceFeePo = BeanConvertUtil.covertBean(reqJson, HousekeepingResourceFeePo.class);
        return saveHousekeepingResourceFeeBMOImpl.save(housekeepingResourceFeePo);
    }

    /**
     * 微信修改消息模板
     * @serviceCode /housekeepingResourceFee/updateHousekeepingResourceFee
     * @path /app/housekeepingResourceFee/updateHousekeepingResourceFee
     * @param reqJson
     * @return
     */
    @RequestMapping(value = "/updateHousekeepingResourceFee", method = RequestMethod.POST)
    public ResponseEntity<String> updateHousekeepingResourceFee(@RequestBody JSONObject reqJson) {

        Assert.hasKeyAndValue(reqJson, "resId", "请求报文中未包含resId");
        Assert.hasKeyAndValue(reqJson, "resName", "请求报文中未包含resName");
        Assert.hasKeyAndValue(reqJson, "configId", "请求报文中未包含configId");
        Assert.hasKeyAndValue(reqJson, "feeName", "请求报文中未包含feeName");
        Assert.hasKeyAndValue(reqJson, "shopId", "请求报文中未包含shopId");
        Assert.hasKeyAndValue(reqJson, "resFeeId", "resFeeId不能为空");


        HousekeepingResourceFeePo housekeepingResourceFeePo = BeanConvertUtil.covertBean(reqJson, HousekeepingResourceFeePo.class);
        return updateHousekeepingResourceFeeBMOImpl.update(housekeepingResourceFeePo);
    }

    /**
     * 微信删除消息模板
     * @serviceCode /housekeepingResourceFee/deleteHousekeepingResourceFee
     * @path /app/housekeepingResourceFee/deleteHousekeepingResourceFee
     * @param reqJson
     * @return
     */
    @RequestMapping(value = "/deleteHousekeepingResourceFee", method = RequestMethod.POST)
    public ResponseEntity<String> deleteHousekeepingResourceFee(@RequestBody JSONObject reqJson) {
        Assert.hasKeyAndValue(reqJson, "shopId", "商铺ID不能为空");

        Assert.hasKeyAndValue(reqJson, "resFeeId", "resFeeId不能为空");


        HousekeepingResourceFeePo housekeepingResourceFeePo = BeanConvertUtil.covertBean(reqJson, HousekeepingResourceFeePo.class);
        return deleteHousekeepingResourceFeeBMOImpl.delete(housekeepingResourceFeePo);
    }

    /**
     * 微信删除消息模板
     * @serviceCode /housekeepingResourceFee/queryHousekeepingResourceFee
     * @path /app/housekeepingResourceFee/queryHousekeepingResourceFee
     * @param shopId 商铺ID
     * @return
     */
    @RequestMapping(value = "/queryHousekeepingResourceFee", method = RequestMethod.GET)
    public ResponseEntity<String> queryHousekeepingResourceFee(@RequestParam(value = "shopId") String shopId,
                                                      @RequestParam(value = "page") int page,
                                                      @RequestParam(value = "row") int row) {
        HousekeepingResourceFeeDto housekeepingResourceFeeDto = new HousekeepingResourceFeeDto();
        housekeepingResourceFeeDto.setPage(page);
        housekeepingResourceFeeDto.setRow(row);
        housekeepingResourceFeeDto.setShopId(shopId);
        return getHousekeepingResourceFeeBMOImpl.get(housekeepingResourceFeeDto);
    }
}
